package rpc.serialize;

import com.google.gson.reflect.TypeToken;
import java.util.Map;
import rpc.utils.JsonUtil;

public class SerializeUtils {

  public static String toJson(Object obj) {

    return JsonUtil.toJson(obj, false);
  }

  public static Map<String, Object> toMap(String json) {
    return JsonUtil.fromJson(json, new TypeToken<Map<String, Object>>() {
    }.getType());
  }

  public static Object toObject(String json, Class<?> clazz) {
    return JsonUtil.fromJson(json, clazz);
  }

  /**
   * *序列化方法
   */
  public static <T> byte[] serialize(T t) {

//		return ProtostuffUtils.serialize(t);
    return ProtostuffSerializeUtil.serialize(t);
//		return  JRedisSerializationUtils.serialize(t);
  }

  /**
   * *反序列化方法
   */
  public static <T> T deSerialize(byte[] data, Class<T> clazz) {
//		return ProtostuffUtils.deserialize(data, clazz);
    return ProtostuffSerializeUtil.deserialize(data, clazz);
//		return  (T)JRedisSerializationUtils.unserialize(data);
  }
}
